<template>
  <el-dialog title="登录信息配置" :width="width"
             :visible.sync="isShowVisible"
             center :close-on-click-modal="false"
             :before-close="() => this.close(false)">
    <el-card>
      <el-form label-width="105px" :model="data" ref="data" :rules="rules" v-loading="isLoading">
        <el-row>
            <el-form-item label="URL:" prop="floginurl" >
              <el-input v-model="data.floginurl"></el-input>
            </el-form-item>
        </el-row>
        <el-row>
            <el-form-item label="用户名:" prop="fuid" >
              <el-input v-model="data.fuid"></el-input>
            </el-form-item>
        </el-row>
        <el-row>
            <el-form-item label="密码:" prop="fpwd" >
              <el-input v-model="data.fpwd"></el-input>
            </el-form-item>
        </el-row>
        <el-row>
            <el-form-item label="数据中心:" prop="fdcname" >
              <el-input v-model="data.fdcname"></el-input>
            </el-form-item>
        </el-row>
        <el-row>
            <el-form-item label="sln:" prop="fslnname" >
              <el-input v-model="data.fslnname"></el-input>
            </el-form-item>
        </el-row>
        <el-row>
            <el-form-item label="数据库类型:" prop="fdbtype" >
              <el-input-number v-model="data.fdbtype"></el-input-number>
            </el-form-item>
        </el-row>
        <el-row>
            <el-form-item label="语言:" prop="flang" >
              <el-input v-model="data.flang"></el-input>
            </el-form-item>
        </el-row>
      </el-form>
    </el-card>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="saveData">保存</el-button>
      <el-button @click="close(false)">取消</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import BaseApi from '@/api/module/BaseApi'
  export default {
    name: 'logineas_edit',
    props:{
      width : {type : String , default : '40vw'},
      fid : {type : Number , },
    },
    data(){
      return{
        isShowVisible : true,
        rules:{
          floginurl: [{ required: true, message: '请填写URL', trigger: 'blur' }],
          fuid : [{required: true, message: '请填写用户名', tirgger: 'blur'}],
          fpwd : [{required: true, message: '请填写密码', tirgger: 'blur'}],
          fdcname : [{required: true, message: '请填写数据中心', tirgger: 'blur'}],
          fslnname : [{required: true, message: '请填写sln', tirgger: 'blur'}],
          fdbtype : [{type: 'number', required: true, message: '请填写数据库类型', tirgger: 'change'}],
          flang : [{required: true, message: '请填写语言', tirgger: 'blur'}],
        },
        data : {},
        isLoading : false,
        api : new BaseApi(),
      }
    },
    mounted(){
    },
    async created(){
      this.isLoading = true
      let data = await this.api.detailLoginEas({fid:this.fid});
      if(data.data==null||data.data==''){
       this.data = {}
      }else{
        this.data =  data.data
      }
      this.isLoading = false
    },
    methods:{
      saveData(){
        this.$refs['data'].validate((valid, object) => {
          if (valid) {
            const loading = this.$loading({
              lock: true,
              text: '请耐心等待.....',
              spinner: 'el-icon-loading',
              background: 'rgba(0, 0, 0, 0.7)'
            })
            this.data.fapiid = this.fid
            this.api.addLoginEas(this.data).then(res => {
                this.$tie.showSuccess(res.message)
                this.close(true)
                loading.close()
            }).catch(e => {
                loading.close()
            })
          }
        })
      },
      close(isOk){
        this.$emit('close',isOk)
      }
    },
  }
</script>
<style scoped>
</style>
